import org.junit.Test;

import java.util.Scanner;

public class work6 {
    //计算闰年
    @Test
    public void test1() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入年份：");
        int year = scanner.nextInt();
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
            System.out.println(year + "年是闰年");
        } else {
            System.out.println(year + "年不是闰年");
        }
    }

    //从控制台输入两个数,然后分别打印这两个数，然后交换这两个数的值
    @Test
    public void test2() {
        int num1 = 3;
        int num2 = 5;
        System.out.println("交换前");
        System.out.println("数字1=" + num1 + "    " + "数字2=" + num2);
        int temp = num1;
        num1 = num2;
        num2 =temp;
        System.out.println("交换后");
        System.out.println("数字1=" + num1 + "    " + "数字2=" + num2);
    }

    //编写一个收银台收款程序
    @Test
    public void test3() {
        Scanner scanner1 = new Scanner(System.in);
        Scanner scanner2 = new Scanner(System.in);
        Scanner scanner3 = new Scanner(System.in);
        System.out.println("请输入单价：");
        System.out.println("请输入数量：");
        System.out.println("用户输入金额：");
        double price = scanner1.nextDouble();   //单价
        int quantity = scanner2.nextInt();  //数量
        double input = scanner3.nextDouble();   //用户输入金额
        double output = price * quantity;   //用户输出金额
        if (output <= input) {
            if (output >= 500) {
                double change = input - output * 0.8;
                System.out.println("找零：" + change);
            } else {
                double change = input - output;
                System.out.println("找零：" + change);
            }
        } else if (output >= 500 && input - output * 0.8 > 0) {
            double change = input - output * 0.8;
            System.out.println("找零：" + change);
        } else {
            System.out.println("用户余额不足");
        }
    }

    //计算1-100以内所有奇数的和以及所有偶数的和，分别打印出来。
    @Test
    public void test4() {
        int even = 0;
        int odd = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                even += i;
            } else {
                odd += i;
            }
        }
        System.out.println("1-100内偶数和为：" + even);
        System.out.println("1-100内奇数和为：" + odd);
    }

    @Test
    public void test5() {
        //你想表达什么意思,就起什么名字
        //int score = 9;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入成绩：");
        int score = scanner.nextInt();
        //卫语句1
        if(score < 0 || score > 100){
            System.out.println("这是非法输入");
            //方法后面的代码不再执行
            return;
        }
        if (score >= 90 && score <= 100) {
            System.out.println("优秀");
        } else if (score >= 80 && score < 90) {
            System.out.println("良好");
        } else if (score >= 70 && score < 80) {
            System.out.println("一般");
        } else if (score >= 60 && score < 70) {
            System.out.println("及格");
        } else {
            System.out.println("不及格");
        }

    }

    @Test
    public void test6(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入单价：");
        double unitPrice = scanner.nextDouble();
        System.out.println("请输入数量：");
        double count = scanner.nextDouble();
        System.out.println("请输入金额：");
        double price = scanner.nextDouble();
        double totalPrice = unitPrice * count;
        if (totalPrice >= 500){
            //totalPrice = totalPrice * 0.8
            totalPrice *= 0.8;
        }
        double returnPrice = price -totalPrice;
        if (returnPrice >= 0){
            System.out.println("找零"+ returnPrice);
        } else {
            System.out.println("钱不够");
        }
    }

}

